/**
 * responsable for setting up the puzzle
 * and all the respective randomized PuzzleCuts and sizes
 * @author jimmy
 *
 */

import java.util.Random;

public class PuzzleCreator {

	/**
	 * a sample puzzle to play with before the parsers
	 * are set and the rest of the program is finished.
	 * and an example for how to program new puzzle creations.
	 * @return PuzzlePiece[]
	 */
	public static PuzzlePiece[] sample()
	{
		PuzzlePiece[] result = new PuzzlePiece[7];
		PuzzleColor color = new PuzzleColor(1f,.5f,0f);


		for(int i = 0; i<7; i++)
		{
			String text = "";
			int value=1;
			switch(i)
			{
				case 0:text="Module Design Process";break;
				case 1:text="Anticipate change identify items likely to change";value = 2;break;
				case 2:text="------Data Representations";value = 3;break;
				case 3:text="------Algorithms";value = 3;break;
				case 4:text="------Input and output formats";value = 3;break;
				case 5:text="Module Interface insensitive to change";value = 2;break;
				case 6:text="If internal details change client modules should not change";break;
			}
			Coordinate location = PuzzleCreator.randomLocation();
			result[i] = new PuzzlePiece(location,color,text,value);
		}
		result[0].setNeighbor(3,result[1],new RoundCut());
		result[1].setNeighbor(1,result[2],new RoundCut());
		result[2].setNeighbor(1,result[3],new SquareCut());
		result[3].setNeighbor(1,result[4],new TriangleCut());
		result[1].setNeighbor(3,result[5],new SquareCut());
		result[5].setNeighbor(3,result[6],new RoundCut());
		return result;
	}
	/**
	 * creates a random location based on the PuzzlePiece size
	 * this must be set before this is called.
	 *
	 */
	public static Coordinate randomLocation()
	{
		Random rand = new Random();
		//between PuzzlePiece.size/10
		//and PuzzlePiece.size*.3
		double lower = (-1);
		double upper = (1-PuzzlePiece.size);
		float x = (float) (rand.nextDouble()*(upper - lower)+lower);
		float y = (float) (rand.nextDouble()*(upper - lower)+lower);
		return new Coordinate(x,y,0);
	}
	/**
	 * creates a random cut for the creation of a puzzle piece
	 * copnnection
	 * @return a cut for a PuzzlePiece
	 */
	public static PuzzleCut randomCut()
	{
		Random rand = new Random();
		double lower = (0);
		double upper = (3);
		float r = (int) (rand.nextDouble()*(upper - lower)+lower);
		PuzzleCut result =  null;
		if(r == 0)
		{
			result = new RoundCut();
		}
		else if(r== 1)
		{
			result = new SquareCut();
		}
		else if(r == 2)
		{
			result = new TriangleCut();
		}
		return result;
	}
}
